import LoginBase from "../LoginBase";
import { JSBridge } from "../JSBridge";

export default class WeiXinLogin extends LoginBase {

    /**
     * 登录
     * @param onFinish 成功获取用户信息返回参数true,否则false
     */
    login(onFinish: Function) {
        super.login(onFinish);
        this.onLoginFinish = onFinish;
        let wx = JSBridge.getWXObj();
        if (!wx) return;
        let _this = this;
        wx.login({
            success(res) {
                _this.session = res.code;
                _this.isLogined = true;
                onFinish && onFinish(true);
            },
            fail(err) {
                console.log('登录失败！' + JSON.stringify(err))
                onFinish && onFinish(false);
            }
        });
    }

}
